<template>
  <div class="out">
    <div class="dailySongs">
      <div class="arrow">
        <i class="iconfont icon-arrow-left" @click="goHome" style="font-size:0.6rem;"></i>
        <i class="iconfont icon-more" style="font-size:0.5rem;"></i>
      </div>
      <div class="dayInfo">
        <div>
          <span style="font-size:0.9rem;font-weight: bold;">30</span>
          <span>/04</span>
          <p> 查看今日运势</p>
        </div>
        <p class="history">历史日推</p>
      </div>
    </div>

    <div class="SongLists">
      <div class="list1">
        <i class="iconfont icon-shipinbofang-" style="font-size:0.45rem;color: #000;"></i>
        <span style="font-size:0.25rem;margin-left: 0.1rem;">播放全部</span>
      </div>
      <div class="songItem" v-for="(item,index) in songList" :key="index" @click="goPlayMusic(index)">
        <img :src="item.pic" style="width: 0.7rem;height: 0.7rem;border-radius: 0.15rem;"/>
        <div style="margin-left: 0.18rem;width: 5.1rem;">
          <p style="font-weight: 400;">{{item.name}}</p>
          <p style="text-overflow: ellipsis;white-space: nowrap;width: 5rem;overflow: hidden;">{{item.writer}} - {{item.name}}</p>
        </div>
        <div>
          <i class="iconfont icon-bofangshipin" style="font-size:0.45rem;margin-right: 0.2rem;"></i>
          <i class="iconfont icon-more" style="font-size:0.4rem;"></i>
        </div>
      </div> 
    </div>
  </div>
  
</template>

<script>
import axios from 'axios'
import {onBeforeMount,reactive,toRefs} from 'vue'
import {useRouter} from 'vue-router'

export default{
  setup() {
    const state=reactive({
       songList:[]
    })
    onBeforeMount(async() => {
       let resultList=await axios.get('/dailySongs.json').then(res=>res.data.data.dailySongs);
       console.log(resultList);
       resultList.forEach(res => {
         let song={id:"",name:"",writer:"",pic:""};
         song.id=res.id;
         song.name=res.name;
         song.writer=res.ar[0].name;
         song.pic=res.al.picUrl;
         state.songList.push(song);
         console.log(song);
       });
    })
    const router=useRouter();
    const goHome=()=>{
      router.go(-1);
    }
    const goPlayMusic=(index)=>{
      router.push({
            path:'/playSong',
            query:{
                index:state.songList[index].id,
                pic:state.songList[index].pic,
                name:state.songList[index].name,
                writer:state.songList[index].writer
            }
      })
    }
    return{
      ...toRefs(state),
      goHome,goPlayMusic
    }
  }
}
</script>

<style scoped>
*{
  color: white;
}
.out{
  background: url(../assets/bg.jpg);
  background-size:cover;
  width: 7.5rem;
  height: 13.34rem;
  overflow: auto;
}
.dailySongs{
  width: 7.5rem;
  height: 4.5rem;
  background: url('@/assets/ds_img1.png');
  background-size:cover;
}
.arrow{
  display: flex;
  justify-content: space-between;
  padding-top: 0.2rem;
}
.dayInfo{
  margin-top: 1.8rem;
  padding-left:0.3rem ;
  display: flex;
  justify-content: space-between;
}
.history{
  background-color: rgba(255,255,255,0.2);
  padding: 0.12rem 0.18rem;
  height: fit-content;
  border-radius: 0.2rem;
  position: relative;
  left: -0.2rem;
  top:0.5rem
}
.SongLists{
  width: 7.2rem;
  height: 10rem;
  margin: 0.15rem 0.15rem;
}
.list1{
  height: 0.4rem;
  display: flex;
  align-items: center;
  margin-bottom: 0.22rem;
}
.songItem{
  height: 0.8rem;
  margin:0.12rem 0 0.12rem 0.12rem;
  display: flex;
  align-items: center;
}
</style>
